package net.zhnb.dao.impl;

import java.util.List;

import finaler.util.Page;
import finaler.util.PageList;
import finaler.util.SQLUtil;
import net.zhnb.bean.Room;
import net.zhnb.dao.RoomDao;

public class RoomDaoImpl extends MiddleAbstractDao<Room> implements RoomDao {

	@Override
	protected Class<Room> getEntityClass() {
		return Room.class;
	}

	@Override
	public PageList getPageList(Page page) throws Exception {
		StringBuffer whereSql = new StringBuffer();
		whereSql.append(" where 1 = 1");
		PageList pageList = new PageList(page);//固定
		StringBuffer sqlCount = new StringBuffer();
		sqlCount.append("select count(1) from room");
		sqlCount.append( whereSql );
		int dataCount = super.getIntBySql( sqlCount.toString() );//取总
		pageList.setTotal(dataCount);//总数
		
		StringBuffer queryListSql = new StringBuffer();
		queryListSql.append(" select * ");
		queryListSql.append(" from room  ");
		queryListSql.append( whereSql );
		queryListSql.append(" order by id desc");
		SQLUtil pageSQL = new SQLUtil(queryListSql);//固定
		pageSQL.setFirstResult( page.getStart() );//固定
		pageSQL.setMaxResults( page.getRange() );//固定
		List<Room> dataList = super.findBySqlToBeanList(pageSQL.getSql());//数据集
		pageList.setList(dataList);
		return pageList;
	}
	

}
